package com.cloud.system.api.web;

import com.cloud.system.api.bean.*;
import com.cloud.system.api.entity.UnitInfo;
import com.cloud.system.api.service.HumanInfoService;
import com.cloud.system.api.service.SysConfigService;
import com.cloud.system.api.service.SystemCacheService;
import com.cloud.system.api.service.UnitInfoService;
import com.cloud.system.common.result.QkIcon;
import com.cloud.system.common.result.SelectItem;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("system/interface/")
public class SystemInterfaceController {

    @Autowired
    private SystemCacheService systemCacheService;

    @Autowired
    private HumanInfoService humanInfoService;

    @Autowired
    private UnitInfoService unitInfoService;

    @Autowired
    private SysConfigService sysConfigService;

    @RequestMapping("sysdict/dicts")
    public Map<String, List<SelectItem>> loadDicts(@RequestBody List<String> keys){
    	Map<String, List<SelectItem>> rtnValue = new HashMap<String, List<SelectItem>>();
    	for(String key : keys){
    		rtnValue.put(key, systemCacheService.loadSelectItem(key));
    	}
    	return rtnValue;
    }
    
    @RequestMapping("sysdict/listdicts")
    public List<SelectItem> listDictItems(String dictKey) {
        return systemCacheService.loadSelectItem(dictKey);
    }

    @RequestMapping("sysconfig/item")
    public String loadSysConfigItem(String configKey) {
        return systemCacheService.loadSysConfigItem(configKey);
    }

    @RequestMapping("humanunit/detail")
    public HumanDetail loadHumanUnitDetail(long humanId) {
        return humanInfoService.loadHumanUnitDetail(humanId);
    }

    @RequestMapping("domains/load")
    public List<SelectItem> loadDomains(long unitId) {
        return systemCacheService.loadUnitDomains(unitId);
    }

    @RequestMapping("domains/loadUnitDomainsByUnitId")
    public List<SelectItem> loadUnitDomainsByUnitId(long unitId) {
        return systemCacheService.loadUnitDomainsByUnitId(unitId);
    }

    @RequestMapping("human/searchlawyer")
    public List<HumanDetail> searchLawyers(long unitId, String query){
        return humanInfoService.searchLawyers(unitId, query);
    }

    /**
     * 部门级别统计
     *
     * @return
     */
    @RequestMapping("getUnitLevelStat")
    public List<Map<String, Object>> getUnitLevelStat(Integer isSupervise,Long unitID) {
        return unitInfoService.getUnitLevelStat(isSupervise,unitID);
    }

    /**
     * 监督部门级别统计
     *
     * @return
     */
    @RequestMapping("getSupUnitLevelStat")
    public List<Map<String, Object>> getSupUnitLevelStat(Long unitID) {
        return unitInfoService.getSupUnitLevelStat(unitID);
    }

    /**
     * 内设监督机构级别统计
     *
     * @return
     */
    @RequestMapping("getInnerSupUnitLevelStat")
    public List<Map<String, Object>> getInnerSupUnitLevelStat(Long unitID) {
        return unitInfoService.getInnerSupUnitLevelStat(unitID);
    }

    /**
     * 部门性质统计
     *
     * @return
     */
    @RequestMapping("getUnitNatureStat")
    public List<Map<String, Object>> getUnitNatureStat(Integer isSupervise, Long unitID) {
        return unitInfoService.getUnitNatureStat(isSupervise, unitID);
    }

    /**
     * 部门区域统计
     *
     * @return
     */
    @RequestMapping("getUnitAreaStat")
    public List<Map<String, Object>> getUnitAreaStat(Integer isSupervise, Long unitID) {
        return unitInfoService.getUnitAreaStat(isSupervise, unitID);
    }

    /**
     * 主体类别统计
     *
     * @return
     */
    @RequestMapping("getLawSubjectStat")
    public List<Map<String, Object>> getLawSubjectStat(Long unitID) {
        return unitInfoService.getLawSubjectStat(unitID);
    }

    /**
     * 委托机构方式统计
     *
     * @return
     */
    @RequestMapping("getEntrustUnitStat")
    public List<Map<String, Object>> getEntrustUnitStat(Long unitID) {
        return unitInfoService.getEntrustUnitStat(unitID);
    }

    /**
     * 委托机构性质统计
     *
     * @return
     */
    @RequestMapping("getEntrustNatureStat")
    public List<Map<String, Object>> getEntrustNatureStat(Long unitID) {
        return unitInfoService.getEntrustNatureStat(unitID);
    }

    /**
     * 执法人员学历统计
     * isSupervise  =1  标识监督部门的统计
     * @return
     */
    @RequestMapping("getPatrolEduStat")
    public List<Map<String, Object>> getPatrolEduStat(Integer isSupervise) {
        return humanInfoService.getPatrolEduStat(isSupervise);
    }

    /**
     * 执法人员性质统计
     *
     * @return
     */
    @RequestMapping("getPatrolNatureStat")
    public List<Map<String, Object>> getPatrolNatureStat() {
        return humanInfoService.getPatrolNatureStat();
    }

    /**
     * 执法类型统计
     *
     * @return
     */
    @RequestMapping("getPatrolLawTypeStat")
    public List<Map<String, Object>> getPatrolLawTypeStat(Integer isSupervise) {
        return humanInfoService.getPatrolLawTypeStat(isSupervise);
    }

    /**
     * 执法队员性别统计
     *
     * @return
     */
    @RequestMapping("getPatrolGenderStat")
    public List<Map<String, Object>> getPatrolGenderStat(Integer isSupervise) {
        return humanInfoService.getPatrolGenderStat(isSupervise);
    }

    /**
     * 执法队员区域统计
     *
     * @return
     */
    @RequestMapping("getPatrolAreaStat")
    public List<Map<String, Object>> getPatrolAreaStat(Integer isSupervise) {
        return humanInfoService.getPatrolAreaStat(isSupervise);
    }

    /**
     * 执法证统计
     *
     * @return
     */
    @RequestMapping("getPatrolCardStat")
    public List<Map<String, Object>> getPatrolCardStat() {
        return humanInfoService.getPatrolCardStat();
    }


    /**
     * 是否拥有执法证统计
     *
     * @return
     */
    @RequestMapping("getLawyerStat")
    public List<Map<String, Object>> getLawyerStat() {
        return humanInfoService.getLawyerStat();
    }


    /**
     * 是否公职律师统计
     *
     * @return
     */
    @RequestMapping("getObtainLawCardStat")
    public List<Map<String, Object>> getObtainLawCardStat() {
        return humanInfoService.getObtainLawCardStat();
    }

    /**
     * 部门区域统计-大屏
     *
     * @return
     */
    @RequestMapping("getUnitAreaStatForScreen")
    public Map<String, Object> getUnitAreaStatForScreen(Integer isSupervise,Long regionid) {
        return unitInfoService.getUnitAreaStatForScreen(isSupervise,regionid);
    }
    /**
     * 执法队员区域统计-大屏
     *
     * @return
     */
    @RequestMapping("getPatrolAreaStatForScreen")
    public  Map<String, Object> getPatrolAreaStatForScreen(Integer isSupervise,Long regionid) {
        return humanInfoService.getPatrolAreaStatForScreen(isSupervise,regionid);
    }

    /**
     * 获取所有省市级信息-大屏
     *
     * @return
     */
    @RequestMapping("getUnitInfoForProvince")
    public  List<Map<String, Object>> getUnitInfoForProvince(Long unitId) {
        return unitInfoService.getUnitInfoForProvince(unitId);
    }

    /**
     * 获取所有区域职权法律法规code码 -大屏
     * @param unitCode
     * @return
     */
    @RequestMapping("getUnitPowerListForLawCode")
    public  List<Map<String, Object>> getUnitPowerListForLawCode(String unitCode,Long regionid) {
        return unitInfoService.getUnitPowerListForLawCode(unitCode,regionid);
    }

    /** 获取地址
     *
     * @return
     */
    @RequestMapping("address/load")
    public List<SelectItem> loadAddressItems(){
        return systemCacheService.loadAddressItems();
    }

    /**
     * 加载部门人员
     * @return
     */
    @RequestMapping("human/load")
    public List<SelectItem> loadHuman(@RequestParam("unitId") Long unitId){
        return systemCacheService.loadHuman(unitId);
    }

    /**
     * 查找检查事项
     * @return
     */
    @RequestMapping("search/checkitem")
    public PageInfo<SuperviseBean> searchCheckItem(@RequestBody RecCheckUnitCriteriaBean recCheckUnitCriteriaBean){
        return systemCacheService.searchCheckItem(recCheckUnitCriteriaBean);
    }

    /**
     * 查找行政处罚监管事项
     * @return
     */
    @RequestMapping("searchsuperviseitem")
    public PageInfo<SuperviseBean> searchSuperviseItem(@RequestBody RecPunishSuperviseItemCriteriaBean recPunishSuperviseItemCriteriaBean){
        return systemCacheService.searchSuperviseItem(recPunishSuperviseItemCriteriaBean);
    }
    
    
    /**
     * 流程批转细化到人
     */
    @RequestMapping("human/transsearch")
    public List<WfActPart> transSearch(String partType, long partId, long unitId, boolean filter){
    	return humanInfoService.transSearch(partType, partId, unitId, filter);
    }

    /**
     * 查询当前登陆者的所属主体领域
     */
    @RequestMapping("unitInfo/findSubjectDomain")
    public List<SelectItem> findSubjectDomain(long unitId){
        return systemCacheService.findSubjectDomain(unitId);
    }

    /**
     * 记载移交机构
     * @param criteria
     * @return
     */
    @RequestMapping("unitInfo/listunitinfopage")
    public PageInfo<UnitInfo> listUnitInfoPage(@RequestBody UnitCriteriaBean criteria) {
        return unitInfoService.listUnitInfoPage(criteria);
    }

    /**
     * 加载机构管理员信息
     * @param unitId
     * @return
     */
    @RequestMapping("humanInfo/gethumaninfobyunitid")
    public HumanDetail getHumanInfoByUnitId(@RequestParam("unitId") long unitId) {
        return humanInfoService.getHumanInfoByUnitId(unitId);
    }

    @RequestMapping("getsystemUrl")
    public String getSystemUrl() {
        return sysConfigService.getSystemUrl();
    }
}
